#ifndef SIMPLE_SUPPORT_ALGORITHM_VMISMATCH_HPP
#define SIMPLE_SUPPORT_ALGORITHM_VMISMATCH_HPP

#include <type_traits> // std::enable_if_t
#include <tuple> // std::apply

#include "traits.hpp" // is_iterable_v
#include "reaches.hpp" // reaches

namespace simple::support
{

	// if tuples were not just an afterthought
	template <typename Vit,
		std::enable_if_t<is_iterable_v<Vit>>* = nullptr>
		// TODO: is tuple-like *begin, tuple_size != 0
	[[nodiscard]] constexpr
	auto mismatch(Vit begin, const Vit& end)
	// TODO: noexcept(...)
	{
		auto all_the_same = [](auto&& tuple)
		{
			return std::apply([](auto&& first, auto&& ... rest)
			{
				return ((rest == first) && ...);
			}, tuple);
		};

		while(not reaches(begin, end) && all_the_same(*begin))
			++begin;
		return begin;
	}

} // namespace simple::support

#endif /* end of include guard */
